package com.mmy.dao.plane;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.mmy.domain.plane.TPlaneAirport;

public interface TPlaneAirportRepository extends JpaRepository<TPlaneAirport, Integer> {
	/**
	 * 获取最大值ID
	 * 
	 * @return 返回值说明 最大ID
	 * @author 创建人hanxl
	 * @date 创建日期 2021.03.17
	 */
	@Query(value = "SELECT MAX(iAirportID) FROM tPlaneAirport WHERE LEFT(iAirportID,2) = RIGHT(YEAR(NOW()),2)", nativeQuery = true)
	Object getMaxAirportID();

	/**
	 * 新增
	 * 
	 * @return 返回值说明
	 * @author 创建人hanxl
	 * @date 创建日期 2021.03.17
	 */

	@Transactional
	@Modifying
	@Query(value = "INSERT INTO tPlaneAirport(iAirportID, cAirportName, iZoneID, dCreateDate, cCreator, dModifyDate, cReviser, cMemo, cSpare1, cSpare2, cSpare3, cSpare4, cSpare5) VALUES (:airportID, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)", nativeQuery = true)
	void save(@Param("airportID") int airportID);

	/*
	 * 根据id删除
	 */
	@Transactional
	@Modifying
	@Query(value = "delete from tPlaneAirport where tPlaneAirport.iAirportID in (:lstAirportID)", nativeQuery = true)
	void delPlaneAirport(@Param("lstAirportID") List<Integer> lstAirportID);

	/**
	 * 根据id查找
	 * 
	 * @return 返回值说明
	 * @author 创建人hanxl
	 * @date 创建日期 2021.03.17
	 */
	@Query(value = "select *  from tPlaneAirport where iAirportID = :iAirportID", nativeQuery = true)
	TPlaneAirport findByAirportID(@Param("iAirportID") int iAirportID);

}
